<template>
	<view class="app">
		<!-- 导航栏 -->
		<u-navbar title="打卡" @rightClick="rightClick" :autoBack="true"></u-navbar>
		<view style="margin-top: 100px;">
			<u--text :text="publicJ"></u--text>
			<u--text :text="publicW"></u--text>
		</view>
		<!-- 底部导航栏 -->
		<u-tabbar :value="tabbarIndex" :placeholder="true">
			<u-tabbar-item text="打卡" icon="map"></u-tabbar-item>
			<u-tabbar-item text="统计" icon="file-text"></u-tabbar-item>
			<u-tabbar-item text="设置" icon="setting"></u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: uni.getStorageSync('img_url'), //获取用户头像
				userName: uni.getStorageSync('worker_name'), //获取用户名字
				newDepartName: uni.getStorageSync('new_depart_name'), //获取用户部门
				tabbarIndex: 0, //底部导航栏索引
				showTime: '',
				t: null, // 定时器属性
				text: '已进入考勤范围：绿港现代农业发展股份有限公司',
				publicJ: '',
				publicW: '',
			};
		},
		mounted() {
			this.t = setTimeout(this.time, 1000);
		},
		methods: {
			rightClick() {

			},
			// 时分秒补全零
			addZero(i) {
				if (i < 10) {
					i = '0' + i;
				}
				return i;
			},
			time() {
				clearTimeout(this.t); //清除定时器
				var dt = new Date();
				var h = this.addZero(dt.getHours()); //获取时，并补全零
				var m = this.addZero(dt.getMinutes()); //获取分，并补全零
				var s = this.addZero(dt.getSeconds()); //获取秒，并补全零
				this.showTime = h + ':' + m + ':' + s;
				this.t = setTimeout(() => this.time(), 1000); //设定定时器，循环运行
			},
		},
		onLoad() {
			var that = this;
			uni.getLocation({
				isHighAccuracy: true, // 开启地图精准定位
				type: 'gcj02', // 坐标系类型
				success: function(res) {
					var latitude = res.latitude; // 维度
					var longitude = res.longitude; // 经度
					console.log('经度：' + longitude + '，纬度：' + latitude);
					// that.form.LATITUDE = latitude;
					// that.form.LONGITUDE = longitude;
					//加偏移
					let x = longitude
					let y = latitude
					let x_pi = (3.14159265358979324 * 3000.0) / 180.0
					let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi)
					let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi)
					let lngs = z * Math.cos(theta) + 0.0065
					let lats = z * Math.sin(theta) + 0.006
					console.log('加偏移后经度：' + lngs + '，加偏移纬度：' + lats);
					that.publicJ = '加偏移后经度' + lngs;
					that.publicW = '加偏移纬度' + lats;
					//加偏移结束
					console.log('当前位置的经度：' + lngs);
					console.log('当前位置的纬度：' + lats);
				},
				fail: function(res) {
					console.log('获取定位失败：' + res.errMsg);
				}
			});
		}
	}
</script>

<style lang="scss">
	.app {
		height: 100vh;
		background-color: #F3F4F5;
		overflow-y: auto;
	}

	.head {
		margin-top: 100rpx;
	}

	.dk {
		background-color: white;
		margin-top: 40rpx;
		height: 70vh;
	}

	.container {
		display: flex;
	}

	.left-part,
	.right-part {
		width: 50%;
		background-color: #EDEDED;
		margin: 20rpx 10rpx 20rpx 20rpx;
		border-radius: 15rpx;

		.spanFist {
			width: 90%;
			padding: 15rpx 15rpx 10rpx 20rpx;
		}

		.spanSecond {
			width: 90%;
			padding: 0rpx 0rpx 10rpx 20rpx;
		}
	}

	.right-part {
		margin: 20rpx 20rpx 20rpx 10rpx;
	}

	.dk_btn {
		margin-top: 450rpx;
	}

	.btn {
		border-radius: 50% !important;
		height: 260rpx !important;
		width: 260rpx !important;
		box-shadow: 20rpx 33rpx 60rpx 20rpx rgba(78, 129, 187, 0.2) !important;
	}

	.flex-container {
		display: flex;
		flex-direction: column;
		/* 设置主轴方向为垂直方向，让子元素纵向排列 */
	}

	.foot {
		margin-top: 40rpx;
	}

	.span_title {
		margin-left: 15rpx !important;
		margin-bottom: 10rpx !important;
	}

	.span_label {
		margin-left: 15rpx !important;
	}
</style>